package com.feicheng.iou.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.feicheng.iou.entity.ResourceRecord;
import com.feicheng.iou.mapper.ResourceRecordMapper;
import com.feicheng.iou.pojo.PersonalDetailPOJO;
import com.feicheng.iou.result.ResultInfo;
import com.feicheng.iou.service.ResourceRecordService;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author tianchunlei
 * @since 2021-06-28
 */
@Service
@Slf4j
@Setter
public class ResourceRecordServiceImpl extends ServiceImpl<ResourceRecordMapper, ResourceRecord> implements ResourceRecordService {

    @Autowired
    private ResourceRecordMapper resourceRecordMapper;  //线索记录映射s

    @Autowired
    private PersonalDetailPOJO personalDetailPOJO;  //个人详情map

    /**
     * @Author wuweinan
     * @Description 查看个人线索详情记录 by resourceId.(这里就是一对多了),返回List<ResourceRecord>,数据库操作.
     * @Date 2021-6-30 9:19
     * @param resourceId
     * @return List<ResourceRecord>
     */
    @Override
    @Transactional
    public ResultInfo selectResourceRecordByResourceId(Integer resourceId) {
        log.info("ResourceRecordServiceImpl的selectResourceRecordByResourceId方法进入");

        //根据线索Id查询线索就列表
        QueryWrapper<ResourceRecord> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("resource_id", resourceId);


        //根据resource_id返回多个resource对象
        List<ResourceRecord> resourceRecords = resourceRecordMapper.selectList(queryWrapper);

        //将结果放入到personalDetailMap中
        personalDetailPOJO.setResourceRecord(resourceRecords);
        log.info("ResourceRecordServiceImpl的selectResourceRecordByResourceId方法返回");

        return ResultInfo.success(personalDetailPOJO);

    }
}
